//
//  SEGBaseCollectionViewCell.m
//  Uhomebk
//
//  Created by 梁昆 on 2017/6/30.
//  Copyright © 2017年 com.segi. All rights reserved.
//

#import "SEGOrderInputCollectionViewCell.h"

@implementation SEGOrderInputCollectionViewCell

- (instancetype)init
{
    if (self == [super init]) {
        [self setupUI];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self == [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

/**
 工单录入菜单界面数据填充
 
 @param inputModel model
 */
-(void)paddDataWithInputModel:(SEGOrderInputModel *)inputModel
{
    NSString *rootUrl = kClientImageRootURL;
    NSString *urlImage = [NSString stringWithFormat:@"%@/%@", rootUrl, inputModel.aliasIcon];
    [self imageView:self.titleImageView setImageUrl:[NSURL URLWithString:urlImage] defaultImage:[UIImage imageWithContentsOfFile:SEGPicName(@"pic_default_300_300")]];
    self.titleLabel.text = inputModel.aliasName;
    self.backgroundColor = kColor_W;
}

-(void)imageView:(UIImageView*)imageView setImageUrl:(NSURL*)url defaultImage:(UIImage*)image
{
    [imageView setImageWithURL:url placeholderImage:image];
}

- (void)setupUI
{
    self.contentView.backgroundColor = kColor_W;
    
    CGSize titleImage_size = CGSizeMake(28, 28);
    [self.contentView addSubview:self.titleImageView];
    [self.titleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.width.mas_equalTo(titleImage_size.width);
        make.height.mas_equalTo(titleImage_size.height);
    }];
    
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleImageView.mas_bottom).mas_offset(10);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(self.contentView).mas_offset(-15);
    }];
    
    [self.contentView addSubview:self.dot];
    [self.dot mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleImageView.mas_top);
        make.left.equalTo(self.titleImageView.mas_right);
        make.size.mas_equalTo(CGSizeMake(7, 7));
    }];
    self.dot.hidden = YES;

    
    self.dot.hidden = NO;
    
    [self.contentView addSubview:self.openIcon];
    [self.openIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleImageView.mas_top);
        make.left.equalTo(self.titleImageView.mas_right);
        make.size.mas_equalTo(CGSizeMake(31, 15));
    }];
    self.openIcon.hidden = YES;
}


#pragma mark - getter
//图片
-(UIImageView *)titleImageView{
    if (!_titleImageView) {
        _titleImageView = [[UIImageView alloc] init];
    }
    return _titleImageView;
}

//文本
-(UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = kFont_13;
        [_titleLabel setTextAlignment:NSTextAlignmentCenter];
        [_titleLabel setTextColor: kColor_1];
    }
    return _titleLabel;
}
//红点
-(UIImageView *)dot{
    if (!_dot) {
        _dot = [[UIImageView alloc] init];
        _dot.image = [UIImage imageWithContentsOfFile:SEGPicName(@"dot_small_r")];
    }
    return _dot;
}

//服务开通标志
-(UIImageView *)openIcon{
    if (!_openIcon) {
        _openIcon = [[UIImageView alloc] init];
        _openIcon.image = [UIImage imageWithContentsOfFile:SEGPicName(@"dot_small_r-1")];
    }
    return _openIcon;
}
@end
